import 'package:built_collection/built_collection.dart';
import 'package:mobile_app.core/core/domain/entities/learning_content/collection_list_item/collection_list_item.dart';
import 'package:mobile_app.core/core/domain/entities/premium_access_status.dart';

abstract class GetPermittedCollectionListItemIds {
  BuiltSet<String> call({
    required BuiltList<CollectionListItem> collectionListItems,
    required PremiumAccessStatus premiumAccessStatus,
  });
}

class GetPermittedCollectionListItemIdsImpl implements GetPermittedCollectionListItemIds {
  const GetPermittedCollectionListItemIdsImpl();

  @override
  BuiltSet<String> call({
    required BuiltList<CollectionListItem> collectionListItems,
    required PremiumAccessStatus premiumAccessStatus,
  }) {
    if (premiumAccessStatus.isInactive) {
      return _limitedAccessPermittedCollectionListItemIds.build();
    }

    final collectionListItemIds = <String>{};

    for (final collectionListItem in collectionListItems) {
      switch (collectionListItem) {
        case Collection():
          final collection = collectionListItem;
          collectionListItemIds.add(collection.id);

        case CollectionFolder():
          final collectionFolder = collectionListItem;

          collectionListItemIds.add(collectionFolder.id);

          final collectionIds = collectionFolder.collections.map((collection) {
            return collection.id;
          });

          collectionListItemIds.addAll(collectionIds);
      }
    }

    return collectionListItemIds.build();
  }
}

const _limitedAccessPermittedCollectionListItemIds = {
  '0c499984-0317-42cc-b88f-e3b9337678ef',
  '86108e71-b5bc-40a2-b9aa-3168b02ed195',
  'eba9d997-93fe-4633-a18e-b6e1d102cff0',
};
